home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / plugins / HTMLWindow.jar / horst / FrameSplitterBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  5.7 KB  |  263 lines

  1. package horst;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Container;
  7. import java.awt.Cursor;
  8. import java.awt.Dimension;
  9. import java.awt.Frame;
  10. import java.awt.Insets;
  11. import java.awt.Point;
  12. import java.awt.Rectangle;
  13. import java.awt.Window;
  14. import java.awt.event.MouseEvent;
  15. import java.awt.event.MouseListener;
  16. import javax.swing.JComponent;
  17. import javax.swing.JPanel;
  18. import javax.swing.UIManager;
  19.  
  20. public class FrameSplitterBar extends JPanel implements MouseListener {
  21.    static final int SPLITTER_WIDTH = 3;
  22.    private int m_orientation = 0;
  23.    private Window m_newPositionBar;
  24.    private boolean m_bResizable = true;
  25.    private int m_size = 3;
  26.  
  27.    public FrameSplitterBar(int orientation) {
  28.       this.m_orientation = orientation;
  29.       ((JComponent)this).setBackground(UIManager.getColor("control"));
  30.       ((Component)this).setCursor(Cursor.getPredefinedCursor(11));
  31.       ((Component)this).enableEvents(48L);
  32.       ((Component)this).addMouseListener(this);
  33.    }
  34.  
  35.    public int getBarSize() {
  36.       return this.m_size;
  37.    }
  38.  
  39.    Window getTraceWindow() {
  40.       if (this.m_newPositionBar == null) {
  41.          Component c = this;
  42.  
  43.          while(!((c = c.getParent()) instanceof Frame)) {
  44.          }
  45.  
  46.          if (c != null) {
  47.             this.m_newPositionBar = new Window((Frame)c);
  48.          } else {
  49.             this.m_newPositionBar = new Window(new Frame());
  50.          }
  51.  
  52.          this.m_newPositionBar.setBackground(Color.yellow);
  53.       }
  54.  
  55.       return this.m_newPositionBar;
  56.    }
  57.  
  58.    public void mouseClicked(MouseEvent e) {
  59.    }
  60.  
  61.    public void mouseEntered(MouseEvent e) {
  62.       if (this.m_bResizable) {
  63.          if (this.m_orientation == 0) {
  64.             ((Component)this).setCursor(Cursor.getPredefinedCursor(11));
  65.          } else {
  66.             ((Component)this).setCursor(Cursor.getPredefinedCursor(8));
  67.          }
  68.  
  69.       }
  70.    }
  71.  
  72.    public void mouseExited(MouseEvent e) {
  73.    }
  74.  
  75.    public void mousePressed(MouseEvent e) {
  76.    }
  77.  
  78.    public void mouseReleased(MouseEvent evt) {
  79.       if (this.m_bResizable) {
  80.          if (this.m_newPositionBar != null) {
  81.             FrameSplitterBar topBar = null;
  82.             FrameSplitterBar leftBar = null;
  83.             FrameSplitterBar rightBar = null;
  84.             FrameSplitterBar bottomBar = null;
  85.             Rectangle splitterBounds = ((Component)this).getBounds();
  86.             Container parent = ((Component)this).getParent();
  87.             Dimension parentDim = ((Component)parent).getSize();
  88.             Insets parentInsets = parent.getInsets();
  89.             Point parentPos = ((Component)parent).getLocationOnScreen();
  90.             if (parent instanceof FrameSetPanel) {
  91.                leftBar = ((FrameSetPanel)parent).getLeftSplitBar(this);
  92.                rightBar = ((FrameSetPanel)parent).getRightSplitBar(this);
  93.                topBar = leftBar;
  94.                bottomBar = rightBar;
  95.             }
  96.  
  97.             int yPos;
  98.             int xPos;
  99.             if (this.m_orientation == 0) {
  100.                xPos = ((Component)this).getLocationOnScreen().x + evt.getX();
  101.                if (leftBar != null) {
  102.                   Point leftPt = ((Component)leftBar).getLocationOnScreen();
  103.                   if (xPos <= leftPt.x + 3) {
  104.                      xPos = leftPt.x + 3 + 1;
  105.                   }
  106.                }
  107.  
  108.                if (rightBar != null) {
  109.                   Point rightPt = ((Component)rightBar).getLocationOnScreen();
  110.                   if (xPos >= rightPt.x) {
  111.                      xPos = rightPt.x - 3;
  112.                   }
  113.                }
  114.  
  115.                if (xPos < parentPos.x + parentInsets.left) {
  116.                   xPos = parentPos.x + parentInsets.left;
  117.                } else if (xPos > parentPos.x + parentDim.width - splitterBounds.width) {
  118.                   xPos = parentPos.x + parentDim.width - splitterBounds.width;
  119.                }
  120.  
  121.                xPos -= parentPos.x;
  122.                yPos = ((Component)this).getBounds().y;
  123.             } else {
  124.                yPos = ((Component)this).getLocationOnScreen().y + evt.getY();
  125.                if (topBar != null) {
  126.                   Point topPt = ((Component)topBar).getLocationOnScreen();
  127.                   if (yPos <= topPt.y + 3) {
  128.                      yPos = topPt.y + 3 + 1;
  129.                   }
  130.                }
  131.  
  132.                if (bottomBar != null) {
  133.                   Point bottomPt = ((Component)bottomBar).getLocationOnScreen();
  134.                   if (yPos >= bottomPt.y) {
  135.                      yPos = bottomPt.y - 3;
  136.                   }
  137.                }
  138.  
  139.                if (yPos < parentPos.y + parentInsets.top) {
  140.                   yPos = parentPos.y + parentInsets.top;
  141.                } else if (yPos > parentPos.y + parentDim.height - splitterBounds.height) {
  142.                   yPos = parentPos.y + parentDim.height - splitterBounds.height;
  143.                }
  144.  
  145.                yPos -= parentPos.y;
  146.                xPos = ((Component)this).getBounds().x;
  147.             }
  148.  
  149.             ((Component)this).setBounds(xPos, yPos, splitterBounds.width, splitterBounds.height);
  150.             ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
  151.             this.m_newPositionBar.dispose();
  152.             this.m_newPositionBar = null;
  153.             ((Container)this).invalidate();
  154.             parent.invalidate();
  155.             parent.validate();
  156.          }
  157.  
  158.       }
  159.    }
  160.  
  161.    protected void processMouseMotionEvent(MouseEvent evt) {
  162.       super.processMouseEvent(evt);
  163.       if (this.m_bResizable) {
  164.          Rectangle splitterBounds = ((Component)this).getBounds();
  165.          Container parent = ((Component)this).getParent();
  166.          Dimension parentDim = ((Component)parent).getSize();
  167.          Insets parentInsets = parent.getInsets();
  168.          Point parentPos = ((Component)parent).getLocationOnScreen();
  169.          FrameSplitterBar leftBar = null;
  170.          FrameSplitterBar rightBar = null;
  171.          FrameSplitterBar topBar = null;
  172.          FrameSplitterBar bottomBar = null;
  173.          if (parent instanceof FrameSetPanel) {
  174.             leftBar = ((FrameSetPanel)parent).getLeftSplitBar(this);
  175.             rightBar = ((FrameSetPanel)parent).getRightSplitBar(this);
  176.             topBar = leftBar;
  177.             bottomBar = rightBar;
  178.          }
  179.  
  180.          if (((AWTEvent)evt).getID() == 506) {
  181.             Window w = this.getTraceWindow();
  182.             if (this.m_orientation == 0) {
  183.                int xPos = ((Component)this).getLocationOnScreen().x + evt.getX();
  184.                int yPos = ((Component)this).getLocationOnScreen().y;
  185.                if (leftBar != null) {
  186.                   Point leftPt = ((Component)leftBar).getLocationOnScreen();
  187.                   if (xPos <= leftPt.x + 3) {
  188.                      xPos = leftPt.x + 3;
  189.                   }
  190.                }
  191.  
  192.                if (rightBar != null) {
  193.                   Point rightPt = ((Component)rightBar).getLocationOnScreen();
  194.                   if (xPos >= rightPt.x) {
  195.                      xPos = rightPt.x - 3;
  196.                   }
  197.                }
  198.  
  199.                if (xPos < parentPos.x + parentInsets.left) {
  200.                   xPos = parentPos.x + parentInsets.left;
  201.                } else if (xPos > parentPos.x + parentDim.width - splitterBounds.width) {
  202.                   xPos = parentPos.x + parentDim.width - splitterBounds.width;
  203.                }
  204.  
  205.                ((Component)w).setBounds(xPos, yPos, splitterBounds.width, splitterBounds.height);
  206.             } else {
  207.                int xPos = ((Component)this).getLocationOnScreen().x;
  208.                int yPos = ((Component)this).getLocationOnScreen().y + evt.getY();
  209.                if (topBar != null) {
  210.                   Point topPt = ((Component)topBar).getLocationOnScreen();
  211.                   if (yPos <= topPt.y + 3) {
  212.                      yPos = topPt.y + 3 + 1;
  213.                   }
  214.                }
  215.  
  216.                if (bottomBar != null) {
  217.                   Point bottomPt = ((Component)bottomBar).getLocationOnScreen();
  218.                   if (yPos >= bottomPt.y) {
  219.                      yPos = bottomPt.y - 3;
  220.                   }
  221.                }
  222.  
  223.                if (yPos < parentPos.y + parentInsets.top) {
  224.                   yPos = parentPos.y + parentInsets.top;
  225.                } else if (yPos > parentPos.y + parentDim.height - 3) {
  226.                   yPos = parentPos.y + parentDim.height - 3;
  227.                }
  228.  
  229.                System.out.println("mousemove yPos =" + yPos);
  230.                ((Component)w).setBounds(xPos, yPos, parentDim.width, 3);
  231.             }
  232.  
  233.             if (!((Component)w).isVisible()) {
  234.                ((Component)w).setVisible(true);
  235.             }
  236.          }
  237.  
  238.       }
  239.    }
  240.  
  241.    public void setBarSize(int sz) {
  242.       this.m_size = sz;
  243.    }
  244.  
  245.    void setOrientation(int orientation) {
  246.       this.m_orientation = orientation;
  247.    }
  248.  
  249.    void setResizable(boolean bResizable) {
  250.       this.m_bResizable = bResizable;
  251.       if (this.m_bResizable) {
  252.          ((Component)this).setCursor(Cursor.getPredefinedCursor(11));
  253.       } else {
  254.          ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
  255.       }
  256.  
  257.    }
  258.  
  259.    void setSize(int width) {
  260.       this.m_size = width;
  261.    }
  262. }
  263.